package com.sjsu.CMPE226.normalized.jdbc.repo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.sjsu.CMPE226.normalized.jdbc.data.Station;

public class StationMapper {

	public static List<Station> decodeAllStations(ResultSet rs) {
		List<Station> station = new ArrayList<Station>();

		try {
			while (rs.next()) {
				Station s = new Station();
				s.setStationId(rs.getString("Station_Id"));
				s.setStationName(rs.getString("Station_Name"));
				s.setElevation(rs.getFloat("Elevation"));

				station.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return station;
	}

	public static PreparedStatement prepareUpdateStationsForSecondaryStation(
			Connection con) throws Exception {
		PreparedStatement psStations = con
				.prepareStatement("Update stations_info set Elevation = 15 " + 
						"where Elevation = 0");

		return psStations;
	}
	
	public static PreparedStatement prepareDeleteStationsForLatitude(Connection con) throws Exception {
		PreparedStatement psStations = con.prepareStatement("Delete from stations_info where Latitude > 60");
		
		return psStations;
	}

}
